package com.wps.wdztv6.common;

import lombok.*;

/**
 * 返回值结果集
 * @param <T> 返回数据类型
 */
@Getter
@Setter
@NoArgsConstructor
@ToString
public class R<T> {
    //0正常
    private int result;
    //提示信息
    private String message;
    //数据
    private T data;

    private R(int result,String message,T data){
        this.result = result;
        this.message = message;
        this.data = data;
    }

    public static <U> R<U> build(int result,String message,U data){
        return new R<>(result,message,data);
    }

    public static <U> R<U> success(U data){
        return new R<>(ResultEnum.SUCCESS.getCode(),"获取成功",data);
    }

    public static <U> R<U> success(String message){
        return new R<>(ResultEnum.SUCCESS.getCode(),message,null);
    }

    public static <U> R<U> success(String message,U data){
        return new R<>(ResultEnum.SUCCESS.getCode(),message,data);
    }

    public static <U> R<U> failed(int result,String message){
        return new R<>(result,message,null);
    }

    public static <U> R<U> failed(String message,U data){
        return new R<>(ResultEnum.ERROR.getCode(), message,data);
    }

    public static <U> R<U> failed(String message){
        return new R<>(ResultEnum.ERROR.getCode(), message,null);
    }
}